/**
 * TODO: 若为【子应用】，此页面仅在本地开发使用。实际登录页请参考【主应用】
 * 若为【独立应用】请删除此注释块
 */
import store from '@/store';
import { BfPage } from '@bud-fe/react-pc-ui';
import { message } from 'antd';
import { useAuth, useHistory } from 'ice';

export default function Login() {
  const history = useHistory();
  const setAuth = useAuth()[1];
  const userDispatchers = store.useModel('user')[1];

  return (
    <BfPage.Login
      // TODO: 主题若为“品牌黄”，设置 type="yellow"
      type="red"
      // TODO: 待替换。logo 相关属性仅 type="red" 时才有
      logo="https://front-static.ab-inbev.cn/middle-platform/20221129/budweiser_logo%402x.png"
      logoStyle={{ width: 200, height: 120 }}
      // TODO: 链接待修改，目前使用的是 bees-force 的。agreement 相关属性仅 type="red" 时才有
      agreement="https://front-static.ab-inbev.cn/bees-force/Confidentiality%20Statement_Vfinal%20for%20FSMD.pdf"
      onLoginSuccess={async (data) => {
        const { autoLogin, ...loginResult } = data;
        const result = await userDispatchers.handleLoginResult({ autoLogin, loginResult });
        if (result) {
          setAuth({ ...result.auth });
          message.success('登录成功');
          setTimeout(() => {
            history.push('/');
          }, 500);
        }
      }}
      onForgetPwd={() => {
        history.push('/forget-pwd');
      }}
    />
  );
}
